home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 1 / PCU0103CD1.iso / entertn / demos / files / aomtrial.exe / AOM / AI / SCN04P2.XS < prev    next >
Encoding:
Text File  |  2002-08-02  |  15.1 KB  |  443 lines

  1. //==============================================================================
  2. // Scn04p2: AI Scenario Script for scenario 4 player 2
  3. //==============================================================================
  4. /*
  5.    AI owner:  Dave Leary
  6.    Scenario owner: Dave Leary
  7.  
  8.     This AI transports existing units to the mainland.
  9.       
  10.     The player defends against waves of attacks from the water consisting of
  11.     pirate ships and krakens.  The pirate ships should drop off several waves of
  12.     land attackers (axemen mostly, one wave of slingers and anubites, and one
  13.     scorpion man in the last group of axemen).  Most of the scenario is handled 
  14.     via trigger, but the three landings are handled by a transport plan that is 
  15.     called with    an AI Func (see "attackLauncher" below).
  16.     
  17.     Each wave is triggered by the destruction of the primary boat or kraken from
  18.     the previous wave.
  19.  
  20.                                   *** DIFFICULTY LEVEL NOTES ***
  21.  
  22.    Easy level - Additional resources provided.  Player starts with four extra
  23.     toxotes.  Attack groups slightly reduced (no anubites).
  24.  
  25.    Moderate level - Base level.  No modifiers.
  26.  
  27.    Difficult level - Shore towers and armory removed.
  28.  
  29.    Nightmare - Shore towers and armory removed.  Many starting toxotes deleted.
  30.     Additional "rearguard" Atlantis towers deleted.  Starting resources seriously
  31.     reduced.
  32.  
  33. */
  34. //==============================================================================
  35. // Set Town Location
  36. //==============================================================================
  37. void setTownLocation(void)
  38. {
  39.    //Look for the "Town Location" marker.
  40.    kbSetTownLocation(kbGetBlockPosition("2639"));
  41. }
  42.  
  43. //==============================================================================
  44. // miscStartup
  45. //==============================================================================
  46. void miscStartup(void)
  47. {
  48.     // Difficulty Level check.
  49.     int difflevel=-1;        
  50.     difflevel=aiGetWorldDifficulty();
  51.  
  52.    //Startup message(s).
  53.    aiEcho("");
  54.    aiEcho("");
  55.    aiEcho("Scn04P2 AI Start, filename='"+cFilename+"'.");
  56.     aiEcho("Difficulty Level="+difflevel+".");
  57.    //Spit out the map size.
  58.    aiEcho("  Map size is ("+kbGetMapXSize()+", "+kbGetMapZSize()+").");
  59.    //Cheat like a bastard.  Once only, though.
  60.    kbLookAtAllUnitsOnMap();
  61.    //Calculate some areas.
  62.    kbAreaCalculate(1200.0);
  63.    //Set our town location.
  64.    setTownLocation();
  65.     //Reset random seed
  66.     aiRandSetSeed();
  67.    //Allocate all resources to the root escrow.
  68.    kbEscrowAllocateCurrentResources();
  69. }
  70.  
  71. //==============================================================================
  72. //==============================================================================
  73. // Attack stuff.
  74. //==============================================================================
  75. //==============================================================================
  76. //Shared variables.
  77.  
  78. int attackerUnitTypeIDSoldier=cUnitTypeAxeman;
  79. int attackerUnitTypeIDTransport=cUnitTypePirateShip;
  80.  
  81. //=========================================================================================
  82. // Kidd's cool configQuery function: used to create attack routes, etc.  Oooh, lovin' that!
  83. //=========================================================================================
  84. bool configQuery( int queryID = -1, int unitType = -1, int action = -1, int state = -1, int player = -1, vector center = vector(-1,-1,-1), bool sort = false, float radius = -1 )
  85. {
  86.    if ( queryID == -1)
  87.    {
  88.       return(false);
  89.    }
  90.  
  91.    if (player != -1)
  92.       kbUnitQuerySetPlayerID(queryID, player);
  93.    
  94.    if (unitType != -1)
  95.       kbUnitQuerySetUnitType(queryID, unitType);
  96.  
  97.    if (action != -1)
  98.       kbUnitQuerySetActionType(queryID, action);
  99.  
  100.    if (state != -1)
  101.       kbUnitQuerySetState(queryID, state);
  102.  
  103.    if (center != vector(-1,-1,-1))
  104.    {
  105.       kbUnitQuerySetPosition(queryID, center);
  106.       if (sort == true)
  107.          kbUnitQuerySetAscendingSort(queryID, true);
  108.       if (radius != -1)
  109.          kbUnitQuerySetMaximumDistance(queryID, radius);
  110.    }
  111.    return(true);
  112. }
  113.  
  114. //=====================================================================================
  115. // Attack Launcher.  This is called from the scenario with an AI Func effect
  116. //=====================================================================================
  117. void attackLauncher(int whichAttack = -1)
  118. {
  119.     int transportPlanID=aiPlanCreate("Transport Group", cPlanTransport);
  120.     // "whichTransport" adds a specific transport to the plans.  Victory conditions, chats, etc.
  121.     // are tied to the concept of the main transport getting whacked.
  122.     int whichTransport=-1;
  123.  
  124.     // Difficulty Level check.
  125.     int difflevel=-1;        
  126.     difflevel=aiGetWorldDifficulty();
  127.  
  128.     vector gatherPoint=kbGetBlockPosition("2638");
  129.     vector targetPoint=kbGetBlockPosition("2642");
  130.     vector initialPosition=kbGetBlockPosition("2639");
  131.  
  132.     int baseID = kbBaseCreate( 2, "mainBase", initialPosition, 50.0);
  133.         
  134.     if (transportPlanID >= 0)
  135.    {
  136.         aiEcho("*** ATTACK LAUNCHER SENDING TRANSPORT ***");
  137.         
  138.         // Different composition depending on which attack.
  139.         switch(whichAttack)
  140.         {    
  141.             case 0:
  142.           {
  143.  
  144.                 whichTransport = kbGetBlockID("2632");
  145.                 aiPlanAddUnitType(transportPlanID, cUnitTypePirateShip, 1, 1, 1);
  146.                 aiPlanAddUnitType(transportPlanID, cUnitTypeAxeman, 5, 5, 5);
  147.                 aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportTypeID, 0, cUnitTypePirateShip);
  148.                 aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportID, 0, whichTransport);
  149.                 break;
  150.             }
  151.  
  152.             case 1:
  153.             {
  154.                 whichTransport = kbGetBlockID("2637");
  155.                 gatherPoint=kbGetBlockPosition("2640");
  156.                 targetPoint=kbGetBlockPosition("2643");
  157.  
  158.                 aiPlanAddUnitType(transportPlanID, cUnitTypePirateShip, 1, 1, 1);
  159.                 aiPlanAddUnitType(transportPlanID, cUnitTypeAxeman, 5, 5, 5);
  160.                 aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportTypeID, 0, cUnitTypePirateShip);
  161.                 aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportID, 0, whichTransport);
  162.                 break;
  163.             }
  164.  
  165.             case 2:
  166.             {
  167.                 whichTransport = kbGetBlockID("2633");
  168.                 gatherPoint=kbGetBlockPosition("2658");
  169.                 targetPoint=kbGetBlockPosition("2641");
  170.  
  171.                 aiPlanAddUnitType(transportPlanID, cUnitTypePirateShip, 1, 1, 1);
  172.                 aiPlanAddUnitType(transportPlanID, cUnitTypeAxeman, 6, 6, 6);
  173.                 
  174.                 if ( difflevel > 0 )
  175.                 {
  176.                     aiPlanAddUnitType(transportPlanID, cUnitTypeSlinger, 2, 2, 2);
  177.                 }
  178.  
  179.                 aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportTypeID, 0, cUnitTypePirateShip);
  180.                 aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportID, 0, whichTransport);
  181.                 break;
  182.             }
  183.  
  184.             case 3:
  185.             {
  186.                 whichTransport = kbGetBlockID("2788");
  187.                 gatherPoint=kbGetBlockPosition("2640");
  188.                 targetPoint=kbGetBlockPosition("2641");
  189.  
  190.                 aiPlanAddUnitType(transportPlanID, cUnitTypePirateShip, 1, 1, 1);
  191.                 aiPlanAddUnitType(transportPlanID, cUnitTypeSlinger, 6, 6, 6);
  192.                 
  193.                 if ( difflevel > 0 )
  194.                 {
  195.                     aiPlanAddUnitType(transportPlanID, cUnitTypeAnubite, 2, 2, 2);
  196.                 }
  197.                 
  198.                 aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportTypeID, 0, cUnitTypePirateShip);
  199.                 aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportID, 0, whichTransport);
  200.                 break;
  201.             }
  202.  
  203.             case 4:
  204.             {
  205.                 whichTransport = kbGetBlockID("2634");
  206.                 gatherPoint=kbGetBlockPosition("2639");
  207.                 targetPoint=kbGetBlockPosition("2785");
  208.  
  209.                 aiPlanAddUnitType(transportPlanID, cUnitTypePirateShip, 1, 1, 1);
  210.                 aiPlanAddUnitType(transportPlanID, cUnitTypeAxeman, 7, 7, 7);
  211.                 aiPlanAddUnitType(transportPlanID, cUnitTypeScorpionMan, 1, 1, 1);
  212.                 aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportTypeID, 0, cUnitTypePirateShip);
  213.                 aiPlanSetVariableInt(transportPlanID, cTransportPlanTransportID, 0, whichTransport);
  214.                 break;
  215.             }
  216.         }
  217.  
  218.         aiPlanSetVariableBool(transportPlanID, cTransportPlanMaximizeXportMovement, 0, true);
  219.         aiPlanSetVariableVector(transportPlanID, cTransportPlanGatherPoint, 0, gatherPoint);
  220.       aiPlanSetVariableVector(transportPlanID, cTransportPlanTargetPoint, 0, targetPoint);
  221.  
  222.         // Setting the base.
  223.         aiPlanSetBaseID( transportPlanID, baseID );
  224.  
  225.         // Don't return when finished.
  226.         aiPlanSetVariableBool(transportPlanID, cTransportPlanReturnWhenDone, 0, false);
  227.  
  228.         // Initial Position
  229.         aiPlanSetInitialPosition( transportPlanID, initialPosition );
  230.         
  231.         aiPlanAddUnit(transportPlanID, whichTransport);
  232.       aiPlanSetActive(transportPlanID);
  233.    }
  234. }
  235.  
  236. //==============================================================================
  237. // initAttack: Creates attack routes, etc.
  238. //==============================================================================
  239. /*
  240. void initAttack(int playerID=-1)
  241. {
  242.    //Destroy all previous attacks (if this isn't the player we're already attacking.
  243.    if (playerID != attackPlayerID)
  244.    {
  245.       //Reset the attack player ID.
  246.       attackPlayerID=-1;
  247.       //Destroy any previous attack plan.
  248.       aiPlanDestroy(attackPlan1ID);
  249.       attackPlan1ID=-1;
  250.       aiPlanDestroy(attackPlan2ID);
  251.       attackPlan2ID=-1;
  252.   
  253.       //Destroy our previous attack paths.
  254.       kbPathDestroy(attackPath1ID);
  255.       attackPath1ID=-1;
  256.       kbPathDestroy(attackPath2ID);
  257.       attackPath2ID=-1;
  258.  
  259.       //Destroy our previous attack routes.
  260.       attackRoute1ID=-1;
  261.       attackRoute2ID=-1;
  262.  
  263.       //Reset the number of attacks.
  264.       numberAttacks=0;
  265.    }
  266.  
  267.    //Save the player to attack.
  268.    attackPlayerID=playerID;
  269.  
  270.    vector gatherPoint=kbGetBlockPosition("3989");
  271.        
  272.     //Setup attack path 1 - go left
  273.    attackPath1ID=kbPathCreate("Attack Path 1");
  274.    kbPathAddWaypoint(attackPath1ID, kbGetBlockPosition("3990"));
  275.     kbPathAddWaypoint(attackPath1ID, kbGetBlockPosition("3991"));
  276.     kbPathAddWaypoint(attackPath1ID, kbGetBlockPosition("3992"));
  277.    //Create attack route 1.
  278.    attackRoute1ID=kbCreateAttackRouteWithPath("Attack Route 1", gatherPoint, kbGetBlockPosition("3995"));
  279.    
  280.     if (attackRoute1ID >= 0)
  281.       kbAttackRouteAddPath(attackRoute1ID, attackPath1ID);
  282.  
  283.    //Setup attack path 2 - go right
  284.    attackPath2ID=kbPathCreate("Attack Path 2");
  285.    kbPathAddWaypoint(attackPath2ID, kbGetBlockPosition("3990"));
  286.     kbPathAddWaypoint(attackPath2ID, kbGetBlockPosition("3991"));
  287.     kbPathAddWaypoint(attackPath2ID, kbGetBlockPosition("3993"));
  288.     kbPathAddWaypoint(attackPath2ID, kbGetBlockPosition("3994"));
  289.    //Create attack route 2.
  290.    attackRoute2ID=kbCreateAttackRouteWithPath("Attack Route 2", gatherPoint, kbGetBlockPosition("3995"));
  291.    
  292.     if (attackRoute2ID >= 0)
  293.       kbAttackRouteAddPath(attackRoute2ID, attackPath2ID);
  294. }
  295. */
  296.  
  297. //==============================================================================
  298. // setupAttack
  299. //==============================================================================
  300. /*
  301. bool setupAttack(int playerID=-1)
  302. {
  303.     int randomPath=aiRandInt(2);
  304.    
  305.     //Info.
  306.     aiEcho("Attacking Player "+playerID+".");
  307.  
  308.    //If the player to attack doesn't match, init the attack.
  309.    if (attackPlayerID != playerID)
  310.    {
  311.       initAttack(playerID);
  312.       if (attackPlayerID < 0)
  313.          return(false);
  314.    }
  315.  
  316.    //Create an attack plan.
  317.    int newAttackPlanID=aiPlanCreate("Attack Player"+attackPlayerID+" Attempt"+numberAttacks, cPlanAttack);
  318.    if (newAttackPlanID < 0)
  319.       return(false);
  320.  
  321.    //Target player (required).  This must work.
  322.    if (aiPlanSetVariableInt(newAttackPlanID, cAttackPlanPlayerID, 0, attackPlayerID) == false)
  323.       return(false);
  324.  
  325.    //Gather point.
  326.     vector gatherPoint=kbGetBlockPosition("3989");
  327.  
  328.     //Set the target type.  This must work.
  329.    if (aiPlanSetNumberVariableValues(newAttackPlanID, cAttackPlanTargetTypeID, 2, true) == false)
  330.       return(false);
  331.  
  332.    //Unit types to attack.
  333.    aiPlanSetVariableInt(newAttackPlanID, cAttackPlanTargetTypeID, 0, cUnitTypeUnit);
  334.     aiPlanSetVariableInt(newAttackPlanID, cAttackPlanTargetTypeID, 1, cUnitTypeBuilding);
  335.  
  336.    //Attack route.
  337.    if (randomPath == 0)
  338.     {
  339.       aiPlanSetVariableInt(newAttackPlanID, cAttackPlanAttackRouteID, 0, attackRoute1ID);
  340.     }
  341.    else
  342.     {
  343.       aiPlanSetVariableInt(newAttackPlanID, cAttackPlanAttackRouteID, 0, attackRoute2ID);
  344.     }
  345.  
  346.    //Set the gather point and gather point distance.
  347.    aiPlanSetVariableVector(newAttackPlanID, cAttackPlanGatherPoint, 0, gatherPoint);
  348.    aiPlanSetVariableFloat(newAttackPlanID, cAttackPlanGatherDistance, 0, 10.0);
  349.  
  350.    //Set up the attack route usage pattern.
  351.    aiPlanSetVariableInt(newAttackPlanID, cAttackPlanAttackRoutePattern, 0, cAttackPlanAttackRoutePatternRandom);
  352.    
  353.     //Add the unit types to the plan.
  354.    aiPlanAddUnitType(newAttackPlanID, attackerUnitTypeID1, attackMinimumGroupSize, attackMaximumGroupSize, attackMaximumGroupSize);
  355.     
  356.    //Set the initial position.
  357.    aiPlanSetInitialPosition(newAttackPlanID, gatherPoint);
  358.    //Plan requires all need units to work (can be false).
  359.    aiPlanSetRequiresAllNeedUnits(newAttackPlanID, true);
  360.    //Activate the plan.
  361.    aiPlanSetActive(newAttackPlanID);
  362.  
  363.    //Now, save the attack plan ID appropriately.
  364.    aiPlanSetOrphan(attackPlan1ID, true);
  365.    attackPlan1ID=newAttackPlanID;
  366.  
  367.    //Increment our overall number of attacks.
  368.    numberAttacks++;
  369. }
  370. */
  371.  
  372. //==============================================================================
  373. // Attack Generator 1 - Axemen and friends
  374. //==============================================================================
  375. /*
  376. rule attackGenerator1
  377.    minInterval 75
  378.    inactive
  379.    group AttackRules
  380.    runImmediately
  381. {
  382.    //See how many "idle" attack plans we have.  Don't create any more if we have
  383.    //idle plans.
  384.    int numberIdleAttackPlans=aiGetNumberIdlePlans(cPlanAttack);
  385.  
  386.    if (numberIdleAttackPlans > 0)
  387.       return;
  388.  
  389.    //If we have enough unassigned military units, create a new attack plan.
  390.    int numberAvailableUnits=aiNumberUnassignedUnits(attackerUnitTypeID1);
  391.    aiEcho("There are "+numberAvailableUnits+" axemen available for a new attack.");
  392.    
  393.     if (numberAvailableUnits >= attackMinimumGroupSize)
  394.         setupAttack(1);
  395. }
  396. */
  397.  
  398.  
  399. //==============================================================================
  400. // Attack enablers - enable attacks after initial timers expire
  401. //==============================================================================
  402. /*
  403. // Axemen
  404. rule attack1Enabler
  405.    minInterval 240
  406.    active
  407.    group AttackRules
  408. {
  409.    xsEnableRule("attackGenerator1");
  410.    xsDisableSelf();
  411. }
  412. */
  413.  
  414. //==============================================================================
  415. // Tech Researching Rules - medium axemen, medium slingers, medium spearmen
  416. //==============================================================================
  417. /*
  418. rule researchMediumAxemen
  419.    minInterval 600
  420.    active
  421. {
  422.    int planID=aiPlanCreate("Medium Axemen research at ten minutes.", cPlanResearch);
  423.    if (planID < 0)
  424.       return;
  425.  
  426.    aiPlanSetVariableInt(planID, cResearchPlanTechID, 0, cTechMediumAxemen);
  427.    aiPlanSetVariableInt(planID, cResearchPlanBuildingTypeID, 0, cUnitTypeBarracks);
  428.    aiPlanSetActive(planID);
  429.    
  430.     //Done.
  431.    xsDisableSelf();
  432. }
  433. */
  434.  
  435. //==============================================================================
  436. // MAIN.
  437. //==============================================================================
  438. void main(void)
  439. {
  440.    //Startup.
  441.    miscStartup();
  442. }
  443.